package cn.edu.neusoft.yuejian13.yuejian_13.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import cn.edu.neusoft.yuejian13.yuejian_13.R;




public class LoginActivity  extends AppCompatActivity implements View.OnClickListener {
    private EditText userphone;
    private EditText password;
    private Button btn_login;
    private TextView btn_reg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        initViews();
        initEvents();
    }

    public void initViews(){
        userphone = (EditText)findViewById(R.id.ed_name);
        password = (EditText)findViewById(R.id.ed_pwd);
        btn_login = (Button)findViewById(R.id.login_btn);
        btn_reg = (Button)findViewById(R.id.reg_btn);
    }
    public void initEvents(){
        btn_login.setOnClickListener(this);
        btn_reg.setOnClickListener(this);

    }


    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.login_btn:
                String name = userphone.getText().toString();
                String pwd = password.getText().toString();
                if (name!=null&&"".equals(name)){
                    Toast.makeText(LoginActivity.this,"请输入帐号！", Toast.LENGTH_SHORT).show();
                }else if(pwd!=null&&"".equals(pwd)){
                    Toast.makeText(LoginActivity.this,"请输入密码！", Toast.LENGTH_SHORT).show();
                }else {
                    Intent intent = new Intent(LoginActivity.this,MainActivity.class);
                    startActivity(intent);
//                  LoginModel loginModel = new LoginModel();
//                  loginModel.login(name, pwd, new TListener<Success>() {
//                      @Override
//                      public void onResponse(Success success) {
//                          if(success.getError().equals("0")){
//                              Intent intent = new Intent(LoginActivity.this,MainActivity.class);
//                              startActivity(intent);
//                          }else{
//                              Toast.makeText(LoginActivity.this,success.getMsg(), Toast.LENGTH_SHORT).show();
//                          }
//                  }
//
//                      @Override
//                      public void onFail(String msg) {
//
//                      }
//                  });
//

                }


                break;
            case R.id.reg_btn:
                Intent intent1 = new Intent(LoginActivity.this,RegisterActivity.class);
                startActivity(intent1);
                break;
        }

    }

}
